#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

int my_atoi(const char* p)
{
	char* str = p;
	assert(p);
	if ((*p < '0' || *p>'9') && (*p != '+' && *p != '-'))
	{
		return 0;
	}
	p++;
	while ( *p > '0' && *p < '9')
	{
		p++;
	}
	p--;
	int ret = 0;
	int j = 1;
	while (p != str)
	{
		ret += (*p - '0') * j;
		j *= 10;
		p--;
	}
	if (*str == '-')
	{
		return -ret;
	}
	else if (*str == '+')
	{
		return ret;
	}
	else
	{
		return ret + ((*str-'0') * j);
	}

}
int main()
{
	char arr[30] = "-123dd1434";
	int ret = my_atoi(arr);
	
	printf("%d", ret);
	return 0;
}
